﻿@{
    ViewBag.Title = "LayoutWiki";
    Layout = "~/Views/Shared/SiteLayout.cshtml";
}
<script type="text/javascript" src="@Url.Content("/Scripts/knockout-2.2.1.js")"></script>
<style type="text/css">
    #menuWiki 
    {
        background-color: gray;
        float:left;
        height: 1500px;
        width: 200px;
    }
    #contentWiki {
        padding: 10px 0 0 0;
        margin: 0 20px 0 0;
    }
</style>
<script type="text/javascript">
    $(document).ready(function() {
        function viewModel1() {
            var self = this;
            $.ajax({
                type: "POST",
                url: "/Wiki/GetProjectList",
                contentType: "application/json",
                dataType: "json",
                async: false,
                success: function(data) {
                    self.projects = data.Projects;
                }
            });
            return self;
        }
        
        var id = $('#routeDataId').val();
        $.getJSON('/Wiki/GetWikiInfo/' + id, function (data) {
            var viewModel = {
                subject: ko.observable(data.WikiInfo.Subject),
                body: ko.observable(data.WikiInfo.Body)
            };
            viewModel.edit = function () {
                var wikiData = {
                    Id: id,
                    Subject: viewModel.subject,
                    Body: $('#txtaBody').val() == '' ? null : $('#txtaBody').val(),
                };
                $.ajax({
                    type: "POST",
                    url: "/Wiki/EditWiki",
                    data: ko.toJSON(wikiData),
                    contentType: "application/json",
                    success: function (data) {
                        alert(data.toString());
                    },
                    error: function () {
                        alert("Failed");
                    }
                });
            };
            ko.applyBindings(viewModel, $("#detail-Wiki")[0]);
        });

        ko.applyBindings(new viewModel1(), $("#menuWiki")[0]);
    });
</script>
<div>
<div id="menuWiki">
    <ul>
        <li><a href="/Wiki/Home">Wiki Home</a></li>
        <li><a href="/Wiki/Guide">Guide</a></li>
        <li><a href="/Wiki/Index">All Pages</a></li>
        <li>
            <a href="#">Project</a>
            <ul data-bind="foreach: projects">
                <li>
                     <a href="#"><span data-bind="text: Name"></span></a>
                </li>
            </ul>
        </li>
        <li><a href="/Wiki/New">New Wiki</a></li>
    </ul>
</div>
<div id="contentWiki">
    @RenderBody()
</div>
</div>